package com.duoqin.chat.ui;

import android.content.ClipData;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.duoqin.chat.Chat;
import com.duoqin.syncassistant.R;

public class ChatFavoritesActivity extends ChatAbsActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        setContentView(R.layout.activity_chat_main);
        setupTitle(getString(R.string.my_favorites));

        initView();
    }

    protected void initView() {
        super.initView();
        findViewById(R.id.divider).setVisibility(View.GONE);
        findViewById(R.id.inputHolder).setVisibility(View.GONE);
        findViewById(R.id.input).setVisibility(View.GONE);
    }

    @Override
    protected void prepareMenuItem(Chat chat) {
        super.prepareMenuItem(chat);
        if (Chat.Columns.CHAT_TYPE_IN.equalsIgnoreCase(chat.type)
                && Chat.Columns.CHAT_MESSAGE_TYPE_VOICE.equalsIgnoreCase(chat.message_type)
                && !TextUtils.isEmpty(chat.message_text)) {
            mMenuList.add(R.string.menu_to_text);
        }
        if (Chat.Columns.CHAT_MESSAGE_TYPE_TEXT.equalsIgnoreCase(chat.message_type)) {
            mMenuList.add(android.R.string.copy);
        }
        mMenuList.add(R.string.menu_delete);
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        CursorLoader loader = new CursorLoader(getApplicationContext(),
                Chat.Columns.FAVORITE_CONTENT_URI, Chat.Columns.CHAT_QUERY_COLUMNS,
                null, null, Chat.Columns.DEFAULT_SORT_ORDER);
        return loader;
    }

    @Override
    protected void onCopyClicked(Chat chat) {
        super.onCopyClicked(chat);
        mClipData = ClipData.newPlainText("DuoqinChat", chat.message_text);
        mClipboardManager.setPrimaryClip(mClipData);
        Toast.makeText(getApplicationContext(), R.string.copy_success, Toast.LENGTH_SHORT).show();
    }
}
